<?php
/**
 * Created by PhpStorm.
 * User: Fedax
 * Date: 2018/7/16
 * Time: 22:36
 */

namespace app\admin\controller;

use app\admin\model\FamilyRoom as FamilyRoomModel;
use app\admin\model\PersonalRoom as PersonalRoomModel;
use app\admin\model\ActivityRoom as ActivityRoomModel;
class Flow extends Index
{
    /**
     * @return \think\response\View
     * 渲染家族房间
     * 帅帅
     */
    public function familyIndex()
    {
        $data = \app\admin\model\Family::field('id,user_id,f_name')->where(['status'=>1,'type'=>1])->select()->toArray();
        foreach($data as $key=>$value){
            $data[$key]['u_id'] = \app\admin\model\User::where('id','=',$value['user_id'])->value('u_id');
        }
        return view()->assign('data',$data);
    }

    /**
     * @return \think\response\Json
     *家族房间数据
     * 帅帅
     */
    public function familyIndexData()
    {
        $familyRoomModel = new FamilyRoomModel();
        $data = $familyRoomModel->getDataList();
        return json($data);
    }

    /**
     * @return array
     * @user shuaishuai wu
     * @date 23:13
     * @title 家族房间删除
     */
    public function flowFamilyRoomDel()
    {
        $familyRoomModel = new FamilyRoomModel();
        $res = $familyRoomModel->flowFamilyRoomDel();
        return $res;
    }

    /**
     * @user 帅帅吴
     * @date 2018/12/29
     * @title 家族房间添加
     */
    public function flowFamilyAdd()
    {
        $familyRoomModel = new FamilyRoomModel();
        $res = $familyRoomModel->flowFamilyAdd();
        if($res['code']==100) $this->success($res['msg']);
        else  $this->error($res['msg']);

    }

    /**
     * @return array
     * @user 帅帅吴
     * @date 2018/12/30
     * @title 家族房间修改
     */
    public function flowFamilyEdit()
    {
        $familyRoomModel = new FamilyRoomModel();
        $res = $familyRoomModel->flowFamilyEdit();
        return  $res;
    }
    /**
     * @return \think\response\View
     * @user:帅帅吴
     * @title:个人房间
     * @time:22018/11/5
     */
    public function personalIndex()
    {
        return view();
    }
    /**
     * @return \think\response\Json
     * @author:帅帅
     * @time:2018/11/5
     * @title:个人房间数据
     */
    public function personalIndexData()
    {
        $personalRoomModel = new PersonalRoomModel();
        $data = $personalRoomModel->getDataList();
        return json($data);
    }

    /**
     * @return array
     * @user 帅帅吴
     * @date 2018/12/30
     * @title 个人房间删除
     */
    public function personalRoomDel()
    {
        $personalRoomModel = new PersonalRoomModel();
        $res = $personalRoomModel->personalRoomDel();
        return $res;
    }

    /**
     * @user 帅帅吴
     * @date 2019/1/1
     * @time 21:47
     * @title 个人房间修改
     */
    public function personalRoomEdit()
    {
        $personalRoomModel = new PersonalRoomModel();
        $newData = input('get.');
        $res = $personalRoomModel->save($newData,['id'=>$newData['id']]);
        if($res) return ['code'=>100,'msg'=>'修改成功'];
        else  return ['code'=>-100,'msg'=>'修改失败'];

    }

    /**
     * @user 帅帅吴
     * @date 2019/12/31
     * @title 个人房间添加
     */
    public function personalRoomAdd()
    {
        $personalRoomModel = new PersonalRoomModel();
        $res = $personalRoomModel->personalRoomAdd();
        if($res['code']==100) $this->success($res['msg']);
        else  $this->error($res['msg']);
    }


    /**
     * @return array
     * @throws \think\exception\DbException
     * @user 帅帅 吴
     * @date 2019/1/1
     * @title 设置个人房间可用不可用
     */
    public function personalRoomChangeStatus()
    {
        $id = input('get.id');
        $personalRoomModel = new PersonalRoomModel();
        $info = $personalRoomModel->get($id);
        $newData['close_time'] = time();   //更改时间
        if($info['status'] == 1) $newData['status'] = 2;
        else $newData['status'] = 1;
        $res = $personalRoomModel->save($newData,['id'=>$id]);
        if($res) return ['code'=>100,'msg'=>'修改成功'];
        else  return ['code'=>-100,'msg'=>'修改失败'];
    }


    //活动房间
    public function activityRoomIndex()
    {
        return view();
    }
    //活动房间数据
    public function activityRoomIndexData()
    {
        $activityRoomModel = new ActivityRoomModel();
        $data = $activityRoomModel->indexData();
        return json($data);
    }

    //删除活动房间
    public function activityRoomDel()
    {
        $activityRoomModel = new ActivityRoomModel();
        $res = $activityRoomModel->activityRoomDel();
        return $res;
    }
    //添加活动房间
    public function activityRoomAdd()
    {
        $activityRoomModel = new ActivityRoomModel();
        $res = $activityRoomModel->activityRoomAdd();
        if($res['code'] == 100 ) $this->success($res['msg']);
        else $this->error($res['msg']);
    }
    //活动房间修改
    public function activityRoomEdit()
    {
        $id = input('id');
        $click_max = input('click_max');
        $activityRoomModel = new ActivityRoomModel();
        $res = $activityRoomModel->save([ 'click_max'=>$click_max],['id'=>$id] );
        if($res) return ['code'=>100,'msg'=>'修改成功'];
        else  return ['code'=>-100,'msg'=>'修改失败'];
    }

}